<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        button{
            margin-top: 10px;
        }
        section .renwu{
            margin-top: 20px;
        }
        section .renwu .liebiao{
            display: flex;
            justify-content: space-between;
        }
    </style>
</head>
<body>
    <section id="app">
        <input type="text" placeholder="请输入任务名称" v-model="inputtext"> <span @click="xinzeng">新增</span><br>
        <main>
            <button>全部任务 <span>{{shuju.length}}</span></button>
            <button>已完成 <span>(0)</span></button>
            <button>未完成 <span>(0)</span></button>
        </main>
        <div class="renwu">
            <h3>任务列表</h3>
            <div class="liebiao" v-for="(item,index) in shuju">
                <input type="checkbox">
                <div>{{item.id}}</div>
                <div>{{item.renwu}}</div>
                <span @click="del(index)">删除</span>
            </div>
            <div v-show="shuju.length==0">呦！小子 没有任务吗？</div>
        </div>
    </section>
</body>
</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v=new Vue({
        el:'#app',
        data:{
            inputtext:'',
            shuju:[
                // {id:1,renwu:''}
            ]
        },
        methods:{
            xinzeng(){
                if(this.inputtext){
                    var obj={
                        id:this.shuju.length+1,
                        renwu:this.inputtext
                    }
                    this.shuju.push(obj)
                    this.inputtext=''
                }
            },
            del(index){
                this.shuju.splice(index,1)
            },
        }
    })
</script>